import { defineStore } from 'pinia'

import $axios from '../tools/axios'

export const useScheduleStore = defineStore('schedule', {
  state: () => {
    return {
      trainno: 'g2604',
      tableData: []
    }
  },
  // 也可以这样定义
  // state: () => ({ count: 0 })
  actions: {
    async loadbyno() {
      this.tableData.length = 0
      console.log(this.trainno)
      const path = '/s/q/byno/' + this.trainno
      const { data: res } = await $axios.get(path)
      if (res.code === 200) {
        this.tableData = res.data
      }
      console.log(res)
    },
    /**
     * 加载数据
     */
    async loadall() {
      const path = '/s/q/all'
      const { data: res } = await $axios.get(path)
      if (res.code === 200) {
        this.tableData = res.data
      }
      console.log(res)
    }
  }
})
